﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;

namespace BZV.Core.Net
{
    // 请求方式定义
    public enum RequestType
    {
        EN_GET,
        EN_POST
    }

    // 请求基本信息定义
    public class RequestInfo
    {
        #region 成员变量定义
        // URL
        string strURL;
        // 请求类型
        string strAccept = @"*/*";
        // 代理
        string strUserAgent = @"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36";
        // 引用
        string strReferer = @"https://kyfw.12306.cn/";
        // 请求方式
        RequestType requstType = RequestType.EN_GET;
        // 连接在线
        String strConnect = "";
        #endregion

        #region 属性定义
        public string URL
        {
            get { return strURL; }
            set { strURL = value; }
        }

        public string Accept
        {
            get { return strAccept; }
            set { strAccept = value; }
        }

        public string UserAgent
        {
            get { return strUserAgent; }
            set { strUserAgent = value; }
        }

        public string Referer
        {
            get { return strReferer; }
            set { strReferer = value; }
        }

        public RequestType Method
        {
            get { return requstType; }
            set { requstType = value; }
        }
        public string Connect
        {
            get { return strConnect; }
            set { strConnect = value; }
        }

        #endregion

        /// <summary>
        /// 返回一个对象
        /// </summary>
        /// <returns></returns>
        public HttpWebRequest GetRequestInstance()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);


            request.Accept = strAccept;


            request.UserAgent = strUserAgent;


            request.Referer = strReferer;

            switch (requstType)
            {
                case RequestType.EN_GET:
                    request.Method = "GET";
                    break;
                case RequestType.EN_POST:
                    request.Method = "POST";
                    break;
            }
            return request;
        }
    }
}
